<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:comps="http://java.sun.com/jsf/composite/components">

	<p:panel
		header="#{locale['crud.cadastro.titulo']} de Paginas do Blog"
		rendered="#{SessaoBean.usuarioAutenticado.blog == null}">
		
		<h:panelGroup layout="block" style="padding: 100px;">

			<h:panelGrid columns="1">
				<h:outputText 
					style="font-size: 2.5em; font-weigth: bold;"
					value="Voce precisa criar um blog para ter acesso a esta funcionalidade" />
				<h:outputText
					style="font-size: 1.5em; font-weigth: bold;"
					value="Acesse a guia 'Gerenciar meu Blog' e descubra como iniciar seu Blog hoje mesmo!" />
			</h:panelGrid>
		
		</h:panelGroup>
			
	</p:panel>

	<h:panelGrid columns="3" columnClasses="topAlign, topAlign, topAlign"
		rendered="#{SessaoBean.usuarioAutenticado.blog != null}">

		<p:panel header="#{locale['crud.cadastro.titulo']}">

			<h:form id="cadastroPostForm">

				<p:commandButton id="cadastrarBtn" icon="ui-icon-document"
					styleClass="ui-priority-primary" update=":tabView:insercaoPostForm"
					value="Publicar #{locale['blog.post.postar']}"
					action="#{UsuarioPostBean.prepararInsercao()}" tabindex="1" />

			</h:form>

		</p:panel>

		<p:spacer style="width: 10px" />

		<p:panel header="#{locale['blog.post.titulo']}"
			style="width: 1060px;">

			<h:form id="listagemPostForm">

				<p:dataTable id="registros" var="registro"
					styleClass="dataTableListagem" widgetVar="blogTable"
					value="#{UsuarioPostBean.posts}" paginator="true" rows="12"
					paginatorPosition="bottom" paginatorAlwaysVisible="true"
					tableStyleClass="tableListagem"
					emptyMessage="#{locale['crud.pesquisa.lista.semResultado']}">

					<p:column sortBy="#{registro.codigo}">

						<f:facet name="header">
							<h:outputText style="padding: 0px 5px 0px 5px;" value="Cod" />
						</f:facet>
						<h:outputText value="#{registro.codigo}" />

					</p:column>

					<p:column sortBy="#{registro.titulo}">

						<f:facet name="header">
							<h:outputText style="padding: 0px 10px 0px 10px;"
								value="#{locale['blog.label.titulo']}" />
						</f:facet>
						<h:panelGroup layout="block" style=" width: 150px;">
							<h:outputText value="#{registro.titulo}" />
						</h:panelGroup>

					</p:column>

					<p:column sortBy="#{registro.conteudo}">

						<f:facet name="header">
							<h:outputText
								value="#{locale['blog.pesquisa.label.conteudo']} (resumo)" />
						</f:facet>
						<h:panelGroup layout="block" style=" width: 665px;">
							<h:outputText value="#{registro.conteudo}" escape="false">
								<f:converter converterId="converter.StringTruncateConverter" />
								<f:attribute name="truncateLimit" value="200" />
							</h:outputText>
						</h:panelGroup>

					</p:column>

					<p:column styleClass="alignCenter">

						<f:facet name="header">
							<h:outputText value="#{locale['crud.pesquisa.lista.acoes']}"
								styleClass="dataTableTextoColunaCabecalho" />
						</f:facet>

						<h:panelGroup layout="block" style="width: 70px;">

							<p:commandButton icon="ui-icon-pencil"
								title="#{locale['crud.botao.editar']}"
								action="#{UsuarioPostBean.prepararEdicao(registro)}"
								update=":tabView:edicaoPostForm"
								oncomplete="edicaoPostDlg.show()" />

							<p:spacer width="5" />

							<p:commandButton icon="ui-icon-trash"
								title="#{locale['crud.botao.excluir']}"
								action="#{UsuarioPostBean.prepararExclusao(registro)}" />

						</h:panelGroup>

					</p:column>

				</p:dataTable>

			</h:form>

		</p:panel>

	</h:panelGrid>

	<p:dialog appendToBody="true" widgetVar="insercaoPostDlg" modal="true"
		showEffect="fade" hideEffect="fade" position="center"
		resizable="false" closable="false" draggable="false">

		<f:facet name="header">
			<h:outputFormat id="tituloInsercao"
				value="#{locale['insercao.titulo']}">
				<f:param value="#{locale['blog.post']}" />
			</h:outputFormat>
		</f:facet>

		<h:form id="insercaoPostForm">
		
			<h:panelGrid columns="1">

			<h:panelGroup layout="block">
				<p:messages id="insercaoPostMsg" closable="true" />
			</h:panelGroup>

			<h:panelGrid columns="2">

				<p:outputLabel id="tituloInsLbl" for="tituloIns"
					value="#{locale['blog.label.titulo']}" />
				<p:inputText id="tituloIns" value="#{UsuarioPostBean.post.titulo}"
					label="#{locale['blog.label.titulo']}"
					onkeypress="limparEspacosExtras(this);" onblur="trim(this);"
					style="width: 600px;" maxlength="200" required="true">
				</p:inputText>

				<p:outputLabel id="resumoEdcLbl" for="resumoEdc"
					value="#{locale['blog.post.resumo']}" />
				<p:inputTextarea id="resumoEdc"
					value="#{UsuarioPostBean.post.conteudoResumo}"
					counter="contadorResumo"
					counterTemplate="#{locale['crud.mensagens.caracteresRestantes']}"
					style="width: 600px; height: 80px;"
					maxlength="2000" required="true" />
				<p:spacer />
				<h:panelGroup layout="block"
					style="text-align: left; margin-bottom: 5px; font-size: 0.8em;">
					<h:outputText id="contadorResumo" />
				</h:panelGroup>

				<p:outputLabel id="conteudoInsLbl" for="conteudoIns"
					value="#{locale['paginaInterna.label.conteudo']}" />
				<p:editor id="conteudoIns" value="#{UsuarioPostBean.post.conteudo}"
					label="#{locale['paginaInterna.label.conteudo']}"
					width="600" height="200"
					required="true" />

			</h:panelGrid>

			<h:panelGroup columns="2" layout="block"
				style="text-align: right; margin-top: 10px; border-top: dotted 1px; padding-top: 10px;">

				<p:commandButton id="salvarIns"
					value="#{locale['crud.botao.salvar']}" icon="ui-icon-disk"
					action="#{UsuarioPostBean.salvarInsercao()}"
					styleClass="ui-priority-primary left" update="insercaoPostForm" />

				<p:commandButton id="cancelarIns"
					value="#{locale['crud.botao.fechar']}" icon="ui-icon-close"
					action="#{UsuarioPostBean.cancelarInsercao()}" styleClass="right"
					immediate="true" />

			</h:panelGroup>

		</h:panelGrid>

		</h:form>

	</p:dialog>

	<p:dialog appendToBody="true" widgetVar="edicaoPostDlg" modal="true"
		showEffect="fade" hideEffect="fade" position="center"
		resizable="false" draggable="false" closable="false">

		<f:facet name="header">
			<h:outputFormat value="#{locale['edicao.titulo']}">
				<f:param value="#{locale['blog.post']}" />
			</h:outputFormat>
		</f:facet>

		<h:form id="edicaoPostForm">

			<h:panelGroup layout="block">
				<p:messages id="insercaoPaginaInternaMsg" closable="true" />
			</h:panelGroup>

			<h:panelGrid columns="2">

				<p:outputLabel id="tituloEdcLbl" for="tituloEdc"
					value="#{locale['blog.label.titulo']}" />
				<p:inputText id="tituloEdc"
					value="#{UsuarioPostBean.post.titulo}"
					label="#{locale['blog.label.titulo']}"
					onkeypress="limparEspacosExtras(this);" onblur="trim(this);"
					style="width: 600px;" maxlength="200" required="true">
				</p:inputText>

				<p:outputLabel id="resumoEdcLbl" for="resumoEdc"
					value="#{locale['blog.post.resumo']}" />
				<p:inputTextarea id="resumoEdc"
					value="#{UsuarioPostBean.post.conteudoResumo}"
					counter="contadorResumo"
					style="width: 600px; height: 80px;"
					counterTemplate="#{locale['crud.mensagens.caracteresRestantes']}"
					maxlength="2000" required="true" />
				<p:spacer />
				<h:panelGroup layout="block"
					style="text-align: left; margin-bottom: 5px; font-size: 0.8em;">
					<h:outputText id="contadorResumo" />
				</h:panelGroup>


				<p:outputLabel id="conteudoEdcLbl" for="conteudoEdc"
					value="#{locale['paginaInterna.label.conteudo']}" />
				<p:editor id="conteudoEdc"
					value="#{UsuarioPostBean.post.conteudo}"
					label="#{locale['paginaInterna.label.conteudo']}"
					width="600" height="200" required="true" />

			</h:panelGrid>

			<h:panelGroup layout="block"
				style="text-align: right; margin-top: 10px; border-top: dotted 1px; padding-top: 10px;">

				<p:commandButton id="salvarEdc"
					value="#{locale['crud.botao.salvar']}" icon="ui-icon-disk"
					styleClass="ui-priority-primary left"
					action="#{UsuarioPostBean.salvarEdicao()}"
					update="edicaoPostForm" />

				<p:commandButton id="cancelarEdc"
					value="#{locale['crud.botao.fechar']}" icon="ui-icon-close"
					action="#{UsuarioPostBean.cancelarEdicao()}"
					update="edicaoPostForm" />

			</h:panelGroup>

		</h:form>

	</p:dialog>

	<comps:confirmacao tituloDialogo="#{locale['crud.alteracoes.titulo']}"
		widgetVar="confirmaAlteracoesEdicaoPostDlg"
		simAction="#{UsuarioPostBean.salvarEdicaoConfirmar()}"
		naoAction="#{UsuarioPostBean.salvarEdicaoCancelar()}"
		simUpdate=":tabView:listagemPostForm :indexGrowl" naoUpdate=""
		scriptOnComplete="confirmaAlteracoesEdicaoPostDlg.hide()">

		<f:facet name="mensagemDialogo">

			<h:outputFormat value="#{locale['crud.alteracoes.pergunta.edicao']}">
				<f:param value="#{locale['paginaInterna.titulo']}" />
			</h:outputFormat>

		</f:facet>

	</comps:confirmacao>

	<comps:confirmacao tituloDialogo="#{locale['crud.excluir.titulo']}"
		widgetVar="confirmaExclusaoPostDlg"
		simAction="#{UsuarioPostBean.excluirConfirmar()}"
		naoAction="#{UsuarioPostBean.excluirCancelar()}"
		simUpdate=":tabView:listagemPostForm :indexGrowl"
		naoUpdate=":indexGrowl"
		scriptOnComplete="confirmaExclusaoPostDlg.hide()">

		<f:facet name="mensagemDialogo">

			<h:outputFormat id="registroExclusao"
				value="#{locale['crud.excluir.pergunta']}">
				<f:param value="#{locale['paginaInterna.titulo']}" />
			</h:outputFormat>

		</f:facet>

	</comps:confirmacao>
</ui:composition>